import React from 'react';
import {WeaSearchGroup, WeaFormItem, WeaBrowser} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import EType from './base/EType';
import ETitle from './base/ETitle';
import ENewsMould from './base/ENewsMould';

// 搜索元素
export default class Content_searchengine extends React.Component {
    state = {
        eNewsFrom: this.props.eNewsFrom
    };

    render() {
        const {eNewsFrom} = this.state;

        let ENewsFrom = <div></div>;
        if (this.props.eShareLevel == '2') {
            ENewsFrom = (
                <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@1ukvh9`} label={getLabel(22919, '新闻来源')} labelCol={{span: 6}} wrapperCol={{span: 16}}>
                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@tygnip`}
                        type={'docnews'}
                        isMultCheckbox={false}
                        isSingle={true}
                        replaceDatas={eNewsFrom}
                        dataParams={{publishtype: 0}}
                        completeParams={{publishtype: 0}}
                        onChange={(ids, names, datas) => this.setState({eNewsFromIds: ids, eNewsFrom: datas})}
                    />
                </WeaFormItem>
            );
        }

        return (
            <div>
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@l89lbb`} title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true}>
                    <EType ecId={`${this && this.props && this.props.ecId || ''}_EType@a5rhr2`} ref="eType" value={this.props.eBaseName}/>
                    {this.props.eShareLevel == '2' ? <ETitle ecId={`${this && this.props && this.props.ecId || ''}_ETitle@y1qp5h`} ref="eTitle" eid={this.props.eid} value={this.props.eTitle} {...this.props}/> : ''}
                    {ENewsFrom}
                    <ENewsMould ecId={`${this && this.props && this.props.ecId || ''}_ENewsMould@i3flh3`} ref="eNewsMould" options={this.props.eNewsMould.options} value={this.props.eNewsMould.selected}/>
                </WeaSearchGroup>
            </div>
        );
    }

    getSaveValues() {
        const {eNewsFrom} = this.state;
        return {
            eContentTitle: this.refs['eTitle'] ? this.refs['eTitle'].getSaveValues() : this.props.eTitle,
            eContentNewsFrom: eNewsFrom && eNewsFrom.length ? eNewsFrom[0].id : '',
            eContentNewsMould: this.refs['eNewsMould'].getSaveValues()
        };
    }
}